﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SvipQuery.Properties;

namespace SvipQuery
{
    public class Helpers
    {
        /// <summary>
        /// 计算Gtk
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string GetGtk(string value)
        {
            var a = 5381;
            for (int s = 0, f = value.Length; s < f; ++s)
            {
                a += (a << 5) + ToUnicode(value, s);
            }
            return (a & 2147483647) + "";
        }

        static int ToUnicode(string str, int s)
        {
            return str[s];
        }

        /// <summary>
        /// 计算32位GTK
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string Get32Gtk(string value)
        {
            return new XJHTTP().RunJsMethod(Resources.gtk, $"'{value}'", "getGtk");
        }
    }
}
